package com.sdy.controller;

import com.github.pagehelper.PageInfo;
import com.sdy.entity.Student;
import com.sdy.service.StudentService;
import com.sdy.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: ssm-sm
 * @author: sdy
 * @create: 2022-12-06 14:27
 **/
@RestController
@RequestMapping("/admin")
public class StudentController {
    @Autowired
    private StudentService studentService;
    @RequestMapping("/showAllPage")
    public R showAll(int pageNum,int pageSize){
        PageInfo<Student> studentPageInfo = studentService.showAll(pageNum, pageSize);
        return R.ok(studentPageInfo);
    }

    @RequestMapping("/delStu")
    public R delStu(int sid){
        int i = studentService.delStu(sid);
        if (i==0){
            return R.fail("删除失败！请联系管理员！");
        }else {
            return R.ok("删除成功！");
        }
    }

    @RequestMapping("/addStu")
    public R addStu(Student student){
        int i = studentService.addStu(student);
        if (i==0){
            return R.fail("添加失败！请联系管理员！");
        }else {
            return R.ok("添加成功！");
        }
    }

    @RequestMapping("/huitian")
    public R huitian(int sid){
        Student student = studentService.queryStudentById(sid);
        return R.ok(student);
    }
    @RequestMapping("/upStu")
    public R updStu(Student student){
        int i = studentService.updStu(student);
        if (i==0){
            return R.fail("修改失败！请联系管理员！");
        }else {
            return R.ok("修改成功！");
        }
    }

}
